package com.six.apidemic.adapter;/*
 *Create by Administrator
 *on 2022/4/19
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.six.apidemic.R;
import com.six.apidemic.bean.ManTrapCallbackBean;
import com.six.apidemic.bean.PersonListCallbackBean;
import com.six.apidemic.databinding.ItemManTrapBinding;
import com.six.apidemic.listener.BaseRecyclerViewHolder;
import com.six.apidemic.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

public class ManTrapAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {
    private List<ManTrapCallbackBean.ResultBean> strings = new ArrayList<>();
    private Context mcontext;
    public OnItemClickListener mOnItemClickLitener;

    public ManTrapAdapter(Context context, List<ManTrapCallbackBean.ResultBean> strings) {
        this.mcontext = context;
        this.strings = strings;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemManTrapBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mcontext),
                R.layout.item_man_trap, parent, false);
        binding.setAdapter(this);
        return new TourViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder holder, final int position) {
        holder.bindData(strings.get(position));
        TourViewHolder tv = (TourViewHolder) holder;

        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return strings.size();
    }

    public class TourViewHolder extends BaseRecyclerViewHolder<ManTrapCallbackBean.ResultBean> {
        ItemManTrapBinding binding;

        public TourViewHolder(ItemManTrapBinding dataBinding) {
            super(dataBinding.getRoot());
            binding = dataBinding;
        }

        @Override
        public void bindData(ManTrapCallbackBean.ResultBean data) {
            binding.setBean(data);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return strings.size();
    }

}